package com.example.demodb.repository;

import com.example.demodb.entity.User;
import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

public interface IUserRepository extends JpaRepository<User, String> {

//    @Modifying
//    @Query("update TodoItem todo "
//            +"set todo.isDone=?2 "
//            +"where todo.id=?1 "
//    )
//    public void update(Long id, Boolean isDone);

    @Transactional
    void deleteById(String id);

    User findUserById(String id);

    User findByNameAndPassword(String username, String password);

    User findByName(String name);

    @Modifying
    @Query("update User user "
            +"set user.name=?2 "
            +"where user.id=?1 "
    )
    void updateUserName(String id,String name);
}
